package com.sbl.bajw.pc.service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.sbl.bajw.common.MyBatisDao;
import com.sbl.bajw.common.web.SessionUnit;
import com.sbl.bajw.mapper.LogScoreModelDao;
import com.sbl.bajw.mapper.OperationLogModelDao;
import com.sbl.bajw.pc.model.LogScoreModel;
import com.sbl.bajw.pc.model.OperationLogModel;

@Service
public class LogScoreModelService {

	@Resource
	private LogScoreModelDao dao;

	@Resource
	private MyBatisDao gridDao;

	@Resource
	private OperationLogModelDao op_dao;
	
	public String getLogScore(){
		String list = gridDao.selectPage(LogScoreModelDao.class, null, "getLogScore");
		
		//积分项列表查询操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("积分项列表查询");
		entity.setOperationname("积分项列表查询");
		entity.setActionid("4");
		op_dao.insert(entity);
		
		return list;
	}
	
	public HashMap<String, Object> getLogScoreModel(String id){
		HashMap<String, Object> map = dao.getLogScoreModel(id);
		
		//单项积分绩效查询操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("单项积分绩效查询");
		entity.setOperationname("单项积分项查询");
		entity.setActionid("4");
		op_dao.insert(entity);
		
		return map;
	}
	
	public void update(String id, String score){
		LogScoreModel model = new LogScoreModel();
		model.setId(id);
		model.setScore(new BigDecimal(Double.parseDouble(score)));
		dao.update(model);
		
		//积分项修改操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("修改积分项");
		entity.setOperationname("积分项修改");
		entity.setActionid("3");
		op_dao.insert(entity);
	}

	public String getUserPerformance(HashMap<String, Object> parm){
		String json = gridDao.selectPage(LogScoreModelDao.class, parm, "getUserPerformance");
		
		//所有用户积分查询操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("所有用户积分查询");
		entity.setOperationname("所有积分查询");
		entity.setActionid("4");
		op_dao.insert(entity);
		
		return json;
	}
	
	public String getUserPerformanceInformation(HashMap<String, Object> parm){
		String json = gridDao.selectPage(LogScoreModelDao.class, parm, "getUserPerformanceInformation");
		
		//积分详情查询操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("积分详情");
		entity.setOperationname("积分详情查询");
		entity.setActionid("4");
		op_dao.insert(entity);
		
		return json;
	}
	
	public List<HashMap<String, Object>> getUserPerformanceById(String id){
		List<HashMap<String, Object>> list = dao.getUserPerformanceById(id);
		
		//APP用户查询积分操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(id);
		entity.setOperationname("APP用户查询积分");
		entity.setOperationname("用户积分查询");
		entity.setActionid("4");
		op_dao.insert(entity);
		
		return list;
	}
	
	public List<HashMap<String, Object>> downloadUserPerformance(HashMap<String, Object> parm){
		List<HashMap<String, Object>> list = dao.getUserPerformance(parm);
		
		//积分列表导出操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("积分绩效导出");
		entity.setOperationname("积分绩效导出");
		entity.setActionid("5");
		op_dao.insert(entity);
		
		return list;
	}
}
